package com.liuhouse.controller;

import com.liuhouse.pojo.Link;
import com.liuhouse.service.ILinkService;
import com.liuhouse.utils.ResponseResult;
import com.liuhouse.vo.PageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/content/link")
public class LinkController {
    @Resource
    private ILinkService linkService;

    //分页查询友情链接列表
    @GetMapping("/list")
    public ResponseResult list(Link link , Integer pageNum , Integer pageSize){
        PageVo pageVo = linkService.selectLinkPage(link, pageNum, pageSize);
        return ResponseResult.okResult(pageVo);
    }


    //增加友情链接
    @PostMapping
    public ResponseResult add(@RequestBody Link link){
        linkService.save(link);
        return ResponseResult.okResult();
    }


    //修改友情链接
    @GetMapping("/{id}")
    public ResponseResult getLinkInfo(@PathVariable("id") Long id){
        Link link = linkService.getById(id);
        return ResponseResult.okResult(link);
    }


    //单独修改友情链接状态
    //目前是没有什么作用的
    @PutMapping("/changeLinkStatus")
    public ResponseResult changeLinkStatus(@RequestBody Link link){
        linkService.updateById(link);
        return ResponseResult.okResult();
    }

    @PutMapping
    //修改友情链接
    public ResponseResult edit(@RequestBody Link link){
        linkService.updateById(link);
        return ResponseResult.okResult();
    }

    //删除友链
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id){
        linkService.removeById(id);
        return ResponseResult.okResult();
    }




}
